
DIR = "f://pys60//"

from sgmllib import SGMLParser
import urllib

class URLLister(SGMLParser):
    def reset(self):                             
        SGMLParser.reset(self)
        self.urls = []
    def start_a(self, attrs):
        href = [("http://www.mobilenin.com/mobilepythonbook/" + v) for k, v in attrs if k=='href' and v.endswith('.py')]
        if href:
            self.urls.extend(href)


usock = urllib.urlopen("http://www.mobilenin.com/mobilepythonbook/examples.html")
parser = URLLister()
parser.feed(usock.read())
usock.close()
parser.close()
for url in parser.urls:
    urllib.urlretrieve(url, DIR + url.split('/')[-1])
    print url
#    print DIR + url.split('/')[-1]
